package cn.edu.hpu.action;


import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.hpu.dao.Where;
import cn.edu.hpu.pojo.Task;
import cn.edu.hpu.pojo.Tasktype;
import cn.edu.hpu.service.TaskService;
import cn.edu.hpu.service.TasktypeService;
import cn.edu.hpu.util.DateUtil;
import cn.edu.hpu.util.SplitString;
import cn.edu.hpu.util.UUIDUtil;

import com.opensymphony.xwork2.ActionSupport;

public class TasktypeAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	private TasktypeService tasktypeService;
	private List<Tasktype> tasktypeList;
	private Tasktype tasktype;
	private String id;
	
	public String execute(){
		//HttpServletRequest request = ServletActionContext.getRequest();
		//List<Where> wheres = Where.builderWhereListByRequest(request);
		//tasktypeList = tasktypeService.findAll(wheres);
		tasktypeList = tasktypeService.findAll();
		return "success";
	}
	
	public String save(){
		Tasktype tt = new Tasktype();
		
		tt.setColor(tasktype.getColor());
		tt.setCreatetime(DateUtil.getTime());
		tt.setType(tasktype.getType());
		tt.setId(UUIDUtil.getUUID());
		
		tasktypeService.save(tt);
		return "success";
	}
	public String update(){
		Tasktype t = new Tasktype();
		
		t.setId(tasktype.getId());
		t.setColor(tasktype.getColor());
		t.setCreatetime(DateUtil.getTime());
		t.setType(tasktype.getType());
		
		tasktypeService.update(t);
			
		
		return "success";
	}
	public String del(){
		tasktypeService.delete(id);
		return "success";
	}
	public String add(){
		return "success";
	}
	public String back(){
		return "success";
	}
	public String edit(){
		tasktype =tasktypeService.findById(id);
		return "success";
	}
	
	//set get
	public TasktypeService getTasktypeService() {
		return tasktypeService;
	}
	@Autowired
	public void setTasktypeService(TasktypeService tasktypeService) {
		this.tasktypeService = tasktypeService;
	}
	public List<Tasktype> getTasktypeList() {
		return tasktypeList;
	}
	public void setTasktypeList(List<Tasktype> tasktypeList) {
		this.tasktypeList = tasktypeList;
	}
	public Tasktype getTasktype() {
		return tasktype;
	}

	public void setTasktype(Tasktype tasktype) {
		this.tasktype = tasktype;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	

	
	
	
}
